package kattas;

import static java.lang.System.currentTimeMillis;
import static kattas.PairOfNumbers.twoNumbers;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class Driver {
	
	private static ExecutorService executor = Executors.newCachedThreadPool();

	public static void main(String[] args) throws InterruptedException {
		final Computable<PairOfNumbers, Integer> computable = new SimpleMultiplier();
		long startTime = currentTimeMillis();
		for (int i = 0; i < 5; i++) {
			executor.execute(new Runnable() {				
				public void run() {
					runCycle(computable);	
				}
			});			
		}
		executor.awaitTermination(60, TimeUnit.SECONDS);
		long endTime = currentTimeMillis();
		long totalTimeTaken = endTime - startTime;
		System.out.println("Total Time taken "+TimeUnit.MILLISECONDS.toSeconds(totalTimeTaken));
	}
	
	
	private static void runCycle(Computable<PairOfNumbers, Integer> computable){
		int one = 123;
		int two = 132;
		int three = 145;
		int four = 151;
		
		PairOfNumbers nos = twoNumbers(one, two);
		Integer result = computable.compute(nos);
		System.out.println(nos+", Result: "+result);
		
		nos = twoNumbers(three, four);
		result = computable.compute(nos);
		System.out.println(nos+", Result: "+result);
		
		nos = twoNumbers(four, one);
		result = computable.compute(nos);
		System.out.println(nos+", Result: "+result);
		
	}
}
